"""
行政区划 Request VO
"""

import utils.enum_utils as enum
from models import (
    ListRequestBase,
    QueryFieldBase,
    RequestBase,
)
from my_typing import *
from utils.validator_utils.pydantic_validator.field import (
    PathCharField,
    QueryCharField,
)


class RegionPathField:
    """ 行政区划 | 路径 | 字段 """

    code: str = PathCharField(..., title="行政区划 编号")


class RegionListRequest(ListRequestBase):
    """" 行政区划 | 列表 | 请求 """

    # -------------------- 排序字段 --------------------
    sort_by_code: enum.MongoSortOrNone = QueryCharField(None, title="根据编号排序")
    sort_by_name: enum.MongoSortOrNone = QueryCharField(None, title="根据名称排序")

    # -------------------- 查询字段 --------------------
    name: StrOrNone = QueryCharField(None, title="名称")
    parent_code: StrOrNone = QueryCharField(None, title="父级编号")

    @classmethod
    def from_query(
        cls,
        page: int = QueryFieldBase.page,
        page_size: int = QueryFieldBase.page_size,
        sort_by_code: enum.MongoSortOrNone = QueryCharField(None, title="根据编号排序"),
        sort_by_name: enum.MongoSortOrNone = QueryCharField(None, title="根据名称排序"),
        name: StrOrNone = QueryCharField(None, title="名称"),
        parent_code: StrOrNone = QueryCharField(None, title="父级编号"),
    ) -> "RegionListRequest":
        return cls(
            page=page,
            page_size=page_size,
            sort_by_code=sort_by_code,
            sort_by_name=sort_by_name,
            name=name,
            parent_code=parent_code,
        )


class RegionDetailRequest(RequestBase):
    """" 行政区划 | 详情 | 请求 """

    code: str = RegionPathField.code
